package com.cn.wanxi.service;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.model.NewsModel;

public class NewsService {
    /**
     * 返回首页的新闻数据
     * @return
     */
    public NewsModel[] getNewsModels() {
//        1.创建空白对象
//        数据必须要给定一个长度
//        长度应该通过dao层数据得到
        NewsDao newsDao = new NewsDao();
        int length = newsDao.titles.length;
//                动态定义数组
        NewsModel[] newsModels = new NewsModel[length];
        for (int i = 0; i < length; i++) {
            NewsModel newsModel = new NewsModel();
            newsModel.setTitle(newsDao.titles[i]);
            newsModel.setContent(newsDao.contents[i]);
            newsModels[i] = newsModel;
        }
        return newsModels;
    }

    /**
     * 返回新闻页面数据
     * @return
     */
    public NewsModel[] getNewsModelsForNewsPage() {
        NewsDao newsDao = new NewsDao();
        int length = newsDao.titlesForNewsPage.length;
//                动态定义数组
        NewsModel[] newsModels = new NewsModel[length];
        for (int i = 0; i < length; i++) {
            NewsModel newsModel = new NewsModel();
            newsModel.setTitle(newsDao.titlesForNewsPage[i]);
            newsModel.setCreateTime(newsDao.createTimeForNewsPage[i]);
            newsModels[i] = newsModel;
        }
        return newsModels;
    }
}
